
function [f,gr] = mr_no_randomNo2(b)

global dat
global dat2
global g
global D
global k

yy=0;
gra=zeros(1,k+0+1);

for i = 1:g
    yt = dat(i).yt;
    wt = dat(i).wt;
    xt = dat(i).xt;
   
    [mr junk] = size(xt);   
     
    
    indp_b1=zeros(mr,1); 
    indp_b2=zeros(mr,1);
    gra_g=zeros(mr,k+0+1); 
  
        bb=xt*b(1:k+0)+b(k+0+1)*ones(mr,1); 
          
        indp_b1=indp_b1+ 1./(1+exp(-2*bb));
        indp_b2=indp_b2+ 1./(1+exp(2*bb));
    
     yy=yy+ ((ones(mr,1)+yt)'/2*log(indp_b1)+(ones(mr,1)-yt)'/2*log(indp_b2));
    
   
        temp4=[xt ones(mr,1)]; 
        gra_g=gra_g+temp4;
        

    gra1=2*((ones(mr,1)+yt)/2-indp_b1)'*gra_g;

    gra=gra+gra1;
end

    f=-yy; 
    gr = -gra';
    